/*****************************************************************************
 * hal_bk72_pwm.c
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/
#include "plum_api.h"
#include "hal/source/hal_bk72/hal_bk72.h"
/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/
#define LOG_RUN_LEVEL LOG_LEVEL_DEBUG
#define LOG_MODULE    "hal.uart"
#include "thirdparty/log/log.h"
/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

#define HAL_BK72_PWM_IDX(id) (bk_pwm_t)(PLUM_HAL_PWM_IDX(id))
/*****************************************************************************
 * Private Types
 ****************************************************************************/

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

/*****************************************************************************
 * Public Functions
 ****************************************************************************/

PLUM_PUBLIC
plum_s32 plum_hal_pwm_init(plum_u32 id, plum_hal_pwm_cof_t *config)
{
    plum_s32 rc = PLEM_ECODE_OK;

    do {
        if (!PLUM_HAL_ID_IS_PWM(id)) {
            LOG_E("the id is not a pwm id");
            rc = PLUM_ECODE_INVALID;
            break;
        }

        if (!config) {
            LOG_E("the config parameter is null");
            rc = PLUM_ECODE_EPARA;
            break;
        }

        rc = bk_pwm_initialize(HAL_BK72_PWM_IDX(id), config->freq,
                               config->freq * config->duty, 0, 0);
        if (rc) {
            LOG_E("bk_pwm_initialize err,rc : %d", rc);
            rc = PLUM_ECODE_EIO;
            break;
        }
    } while (0);

    return (rc);
}

PLUM_PUBLIC
plum_void plum_hal_pwm_suspend(plum_u32 id)
{
    do {
        if (!PLUM_HAL_ID_IS_PWM(id)) {
            break;
        }

        bk_pwm_stop(HAL_BK72_PWM_IDX(id));
    } while (0);
}

PLUM_PUBLIC
plum_void plum_hal_pwm_resume(plum_u32 id)
{
    do {
        if (!PLUM_HAL_ID_IS_PWM(id)) {
            break;
        }

        bk_pwm_start(HAL_BK72_PWM_IDX(id));
    } while (0);
}

PLUM_PUBLIC
plum_s32 plum_hal_pwm_duty_set(plum_u32 id, plum_float duty)
{
}

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
